import {
  joinGroupNotice
} from '../../apis/group';
const app = getApp();

Page({
  data: {
    noticeList: [],
    pageNum: 1,
    isHaveMore: true
  },

  onLoad() {
    this.getNotice(1, 10);
  },

  onReachBottom() {
    if (this.data.isHaveMore) {
      this.setData({
        pageNum: this.data.pageNum + 1
      });
      this.getNotice(this.data.pageNum, 10);
    };
  },

  getNotice(pageNum, pageSize) {
    joinGroupNotice(pageNum, pageSize).then(res => {
      if (res.data.code === 200) {
        let {
          rows,
          total
        } = res.data;
        rows.forEach(v => {
          this.data.noticeList.push(v);
        });
        this.setData({
          noticeList: this.data.noticeList
        });
        if (this.data.noticeList.length === total) {
          this.setData({
            isHaveMore: false
          });
        };
      };
    });
  },

  goGroup(e) {
    let {
      id
    } = e.currentTarget.dataset;
    wx.setStorageSync('selectGroup', JSON.stringify({
      groupId: id
    }));
    wx.switchTab({
      url: `/pages/groupDetails/index`
    });
  }
})